﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace CLUBsInterpreter.AST
{
	
	/**
	 * <summary>
	 * Abstract base-class for all Abstract Syntax Tree nodes.
	 * </summary>
	 **/
	abstract class AbstractSyntaxTree
	{
		protected bool m_visitedOnce = false;

		/**
		 * <summary>
		 * The parent node of this AST node.
		 * </summary>
		 **/
		public AbstractSyntaxTree Parent;

		/**
		 * <summary>
		 * Visit must call the appropriate visit method on the given Visitor object.
		 * </summary>
		 * <param name="v"> The Visitor to use. </param>
		 **/
		public abstract void Visit(Visitor v);

		/**
		 * <summary>
		 * PrintTree must print out relevant data about this node to outStream, assuming a tree-depth of depth.
		 * </summary>
		 * <param name="outStream"> The TextWriter object to print to. </param>
		 * <param name="depth"> The tree-depth of this node. </param>
		 **/
		public abstract void PrintTree(TextWriter outStream, int depth);

		public bool SecondPass
		{
			get { return m_visitedOnce; }
		}

		/**
		 * <summary>
		 * TabDepth is a static function that ensures a common format for tree depth indentation.
		 * </summary>
		 * <param name="depth"> The depth to indent. </param>
		 * <returns> A string to be used for indentation, following the common format. </returns>
		 **/
		public static string TabDepth(int depth)
		{
			// Initialize empty string
			string str = "";
			// Add a string once per depth
			for (int i = 0; i < depth; i++) str += "|-->";
			// Return
			return str;
		}

	}

	/**
	 * <summary>
	 * IdentifierType describes the type of a CLUBs identifier.
	 * Note that Unset is also used for void Actions.
	 * </summary>
	 **/
	enum IdentifierType
	{
		Unset, Board, Cell, Piece, Player, Round, Turn, Action, Integer, String, Boolean, Array, Library, Null
	}

	/**
	 * <summary>
	 * DefinitionType describes the type of a CLUBs definition.
	 * </summary>
	 **/
	enum DefinitionType
	{
		Invalid, Board, Cell, Piece, Player, Round, Turn, Action
	}

	/**
	 * <summary>
	 * Operator describes a CLUBs operator type.
	 * </summary>
	 **/
	enum Operator
	{
		// Invalid operator type -- usually due to parser error
		Invalid,
		// Standard arithmetic
		Plus, Minus, Mult, Div,
		// Comparison
		Is,
		// Boolean inversion
		Not
	}
}
